<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="68px">
      <!--<el-form-item label="采购方总部编码" prop="purchaserHqCode">
        <el-input v-model="queryParams.purchaserHqCode" placeholder="请输入采购方总部编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>-->
      <el-form-item label="生产单号" prop="ipoNo">
        <el-input v-model="queryParams.ipoNo" placeholder="请输入生产订单号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="需求日期" prop="saleDate">
        <el-date-picker clearable
                        v-model="queryParams.saleDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择下单日期">
        </el-date-picker>
      </el-form-item>
      <!--<el-form-item label="种类编码" prop="subclassCode">
        <el-input v-model="queryParams.subclassCode" placeholder="请输入种类编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>-->
      <!--<el-form-item label="排产计划编码" prop="scheduleCode">
        <el-input v-model="queryParams.scheduleCode" placeholder="请输入排产计划编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['develop:FactoryProduceMain:add']">新增</el-button>
      </el-form-item>
    </el-form>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table" >
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="生产订单号"  align="center" prop="ipoNo" />
      <!--  <template slot-scope="scope">
          <router-link  class="link-type">
            <span>{{ scope.row.ipoNo }}</span>
          </router-link>
        </template>
      </el-table-column>-->
      <!--<el-table-column label="销售订单行项目号" width="150" align="center" prop="soItemNo"/>
      <el-table-column label="订单类型" width="150" align="center" prop="ipoType"/>-->
      <!--<el-table-column label="供应商名称" align="center" prop="supplierName"/>&ndash;&gt;
      <el-table-column label="品类编码" width="150" align="center" prop="categoryCode"/>
      <el-table-column label="排产计划编码" width="150" align="center" prop="scheduleCode"/>
      <el-table-column label="厂家物料编码" width="150" align="center" prop="materialsCode"/>
      <el-table-column label="厂家物料名称" width="150" align="center" prop="materialsName"/>
      <el-table-column label="厂家物资单位" width="150" align="center" prop="materialsUnit"/>
      <el-table-column label="厂家物料描述" width="150" align="center" prop="materialsDesc"/>
      <el-table-column label="计量单位" width="150" align="center" prop="unit"/>
      <el-table-column label="产品型号" width="150" align="center" prop="productModel"/>-->
      <!--<el-table-column label="生产数量" width="150" align="center" prop="amount"/>-->
      <el-table-column label="下单日期"  align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="需求日期"  align="center" prop="saleDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.saleDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划开始日期"  align="center" prop="planStartDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planStartDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划完成日期"  align="center" prop="planFinishDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planFinishDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="实际开始日期" width="150" align="center" prop="actualStartDate"/>
      <el-table-column label="实际完成日期" width="150" align="center" prop="actualFinishDate"/>-->
      <el-table-column label="生产工厂名称" align="center" prop="plantName"/>
      <el-table-column label="生产车间名称"  align="center" prop="workshopName"/>
      <el-table-column label="生产订单类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.prod_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="生产订单状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.prodstatus" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="生产中心" width="150" align="center" prop="center"/>
       <el-table-column label="数据来源" align="center" prop="dataSource"/>
       <el-table-column label="来源数据创建时间" align="center" prop="dataSourceCreateTime"/>
       <el-table-column label="数据拥有方" align="center" prop="ownerId"/>
       <el-table-column label="数据可见方" align="center" prop="openId"/>-->
      <el-table-column label="备注" align="center"  prop="remark" show-overflow-tooltip/>
      <!--<el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
      <el-table-column label="操作" align="center"  fixed="right" width="300px">
        <template slot-scope="scope">
          <el-button @click="goodsDoAll(scope.row)" icon="el-icon-reading" size="mini" type="text">
            生产明细
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['develop:FactoryProduceMain:edit']">
            修改
          </el-button>
          <el-button @click="fenpeiNew(scope.row)" icon="el-icon-plus" size="mini" type="text">
            分配任务
          </el-button>
          <el-button @click="GongxuGoodsNew(scope.row)" icon="el-icon-plus" size="mini" type="text">
            设定工序
          </el-button>
          <el-button @click="wuliaoProject(scope.row)" icon="el-icon-plus" size="mini" type="text">
            用料明细
          </el-button>
          <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                         style="margin-left: 10px;">
            <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                       v-hasPermi="['develop:FactoryProduceMain:remove']">删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

    <shengchanProd-form ref="form" @ok="getList"></shengchanProd-form>
    <modify-form ref="modifyForm" @ok="getList"></modify-form>
    <goodsDoAll-form ref="goodsDoAllForm" @ok="getList"></goodsDoAll-form>

    <allocating-task ref="allocatingtask"></allocating-task>
    <process-list ref="processlist"></Process-list>
    <yongliaoMingxi-form-list-porject ref="wuliaoProjectForm" @ok="getList"></yongliaoMingxi-form-list-porject>
  </div>
</template>

<script>

  import { deleteAction, getAction } from '@/api/manage'
  import ShengchanProdForm from '@/views/develop/zizhi/ShengchanProdForm'
  import ModifyForm from '@/views/develop/zizhi/ModifyForm'
  import GoodsDoAllForm from '@/views/develop/zizhi/GoodsDoAllForm'
  import AllocatingTask from "@/views/develop/process/AllocatingTask";
  import ProcessList from "@/views/develop/process/ProcessList";
  import YongliaoMingxiFormListPorject from '@/views/develop/goodsSaleMaterial/module/YongliaoMingxiFormListPorject'

  export default {
    dicts: ['prodstatus','prod_type'],
    name: "ShengchanProdList",
    components: {
      ShengchanProdForm,
      ModifyForm,
      GoodsDoAllForm,
      AllocatingTask,
      ProcessList,
      YongliaoMingxiFormListPorject,
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 生产订单信息表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          status: null,
          purchaserHqCode: null,
          ipoType: null,
          supplierCode: null,
          supplierName: null,
          ipoNo: null,
          categoryCode: null,
          subclassCode: null,
          scheduleCode: null,
          poItemId: null,
          dataType: null,
          soItemNo: null,
          materialsCode: null,
          materialsName: null,
          materialsUnit: null,
          materialsDesc: null,
          amount: null,
          unit: null,
          productIdGrpNo: null,
          productIdType: null,
          productModel: null,
          planStartDate: null,
          planFinishDate: null,
          actualStartDate: null,
          actualFinishDate: null,
          plantName: null,
          workshopName: null,
          ipoStatus: null,
          center: null,
          dataSource: null,
          dataSourceCreateTime: null,
          ownerId: null,
          openId: null,
          saleDate: null,
          type: "0",
          orderByColumn: "ipoNo",
          isAsc: "desc"
        },
        url: {
          list:'/factoryProduceMain/factoryProduceMain/list',
          remove:'/factoryProduceMain/factoryProduceMain/removeNoGoods/',
          export:'/factoryProduceMain/factoryProduceMain/export',
        },
        tableMaxHeight: window.innerHeight - 320,
        };
      },
      created() {
        this.getList();
        window.addEventListener('resize', this.getTableHeight);
      },
      destroyed () {
        window.removeEventListener('resize', this.getTableHeight)
      },
      methods: {
        // 分配任务
        fenpeiNew(row) {
          this.$refs.allocatingtask.handleUpdate(row);
        },
        // 工序选择
        GongxuGoodsNew(row) {
          this.$refs.processlist.handleUpdate(row);
        },
        wuliaoProject(row) {
          this.$refs.wuliaoProjectForm.show(row);
        },
        goodsDoAll(row){
          this.$refs.goodsDoAllForm.show(row);
        },
        /** 查询生产订单信息列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getTableHeight () {
        this.tableHeight = window.innerHeight - 320
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$refs.form.handleAdd();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.$refs.modifyForm.handleUpdate(row);
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const id = row.id ;
        deleteAction(this.url.remove, id).then(response => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(this.url.export, {
          ...this.queryParams
        }, `factoryProduceMain_${new Date().getTime()}.xlsx`)
      },
    }
  };
</script>
